var workConSearch_searchArea="";
var workConSearch_searchPost="";
var userPostId = "";
$( document ).on( "pageshow", "#workConSearch", function( event ) {
	access_token=getParameterByName("access_token", getLocationUrl(event) );
	thisWorkConType = getParameterByName("workConType", getLocationUrl(event) );
	userPostId = getParameterByName("userPostId", getLocationUrl(event));
	if(thisWorkConType == 3){
		workConType = '1';
	}else{
		workConType = thisWorkConType;
	}
	loadAreaAndPost();
	
	
	//重置
	$("#workConSearch_reset_search").on('click', function () {
		workConSearch_searchArea="";
		workConSearch_searchPost="";
		
		$("#workConSearch_areaContent span").each(function(index,domEle){
			$(domEle).removeClass('redBorderSpan');
			if(index==0){
				$(domEle).addClass('redBorderSpan');
			}
		});
		$("#workConSearch_postContent span").each(function(index,domEle){
			$(domEle).removeClass('redBorderSpan');
			if(index==0){
				$(domEle).addClass('redBorderSpan');
			}
		});
	});
	//提交
	$("#workConSearch_submit_search").on('click', function () {
//		alert(workConSearch_searchArea+"======="+workConSearch_searchPost);
		goTo2(rootPath+"/jsp/weixin/workConViewList.jsp?access_token="+access_token+"&workConType="+thisWorkConType
				+"&searchArea="+workConSearch_searchArea+"&searchPost="+workConSearch_searchPost+"&isSearch=1"+"&userPostId="+userPostId,false);
	});
});
$( document ).on( "pagecreate", "#workConSearch", function( event ) {
	access_token=getParameterByName("access_token", getLocationUrl(event) );
	userPostId = getParameterByName("userPostId", getLocationUrl(event));
	//去 我的审阅列表页面
	$("#workConSearch_back").on('click', function () {
		goTo2(rootPath+"/jsp/weixin/workConViewList.jsp?access_token="+access_token+"&workConType="+thisWorkConType+"&userPostId="+userPostId,false);
	});
	
});

//地址域数据
function onClickAreaSpan(areaId,obj){
//	alert($("#workConSearch_areaContent span"));
	//消除所有的状态
	$("#workConSearch_areaContent span").each(function(index,domEle){
		$(domEle).removeClass('redBorderSpan');
	});
	//给选中的赋选中状态
	$(obj).addClass('redBorderSpan');
	workConSearch_searchArea=areaId;
}
//职级域数据
function onClickPostSpan(postId,obj){
	//消除所有的状态
	$("#workConSearch_postContent span").each(function(index,domEle){
		$(domEle).removeClass('redBorderSpan');
	});
	//给选中的赋选中状态
	$(obj).addClass('redBorderSpan');
	workConSearch_searchPost=postId;
}
//加载查询域数据
function loadAreaAndPost(){
	var arr_area=[{'flag':'浙江','name':'浙江'}
				,{'flag':'江苏','name':'江苏'}
				,{'flag':'北京','name':'北京'}
				,{'flag':'河北','name':'河北'}
				,{'flag':'辽宁','name':'辽宁'}
				,{'flag':'四川','name':'四川'}
				,{'flag':'河南','name':'河南'}
				,{'flag':'福建','name':'福建'}
				,{'flag':'山东','name':'山东'}
				,{'flag':'上海','name':'上海'}
				,{'flag':'湖南','name':'湖南'}
				,{'flag':'黑龙江','name':'黑龙江'}
				,{'flag':'江西','name':'江西'}
				,{'flag':'安徽','name':'安徽'}
				,{'flag':'广西','name':'广西'}
				,{'flag':'陕西','name':'陕西'}
				,{'flag':'湖北','name':'湖北'}
				,{'flag':'山西','name':'山西'}
				,{'flag':'内蒙古','name':'内蒙古'}
				,{'flag':'广东','name':'广东'}
				,{'flag':'重庆','name':'重庆'}
				,{'flag':'大连','name':'大连'}
				,{'flag':'厦门','name':'厦门'}
				,{'flag':'宁波','name':'宁波'}
				,{'flag':'天津','name':'天津'}
				,{'flag':'总公司','name':'总公司'}];
	var arr_post=[{'flag':'S','name':'S'}
				,{'flag':'A','name':'A'}
				,{'flag':'B','name':'B'}
				,{'flag':'C','name':'C'}
				,{'flag':'D','name':'D'}
				,{'flag':'E','name':'E'}];
	var areaCon='<span class="searchArea redBorderSpan" flag="" onclick="onClickAreaSpan(\'\',this)">所有</span>';
	var postCon='<span class="searchArea redBorderSpan" flag="" onclick="onClickPostSpan(\'\',this)">所有</span>';
	$.ajax({
	  	url: rootPath+"/workCon/getUserPost.do",
	  	type: "GET",
	  	dataType: "text",
		data: "access_token="+access_token,
	  	success: function( response ) {
	  		var data=$.parseJSON(response);
			if(data.state=="200"){
				var postid = data.data.postid;
				var dept_name = data.data.dept_name;
				var isHeadquarters = false;
				if(dept_name.indexOf("总公司") != -1){
					isHeadquarters = true;
				}
				if(postid == 'S'){
					$("#tr_workConSearch_areaContent").show();
					for(var i=0;i<arr_area.length;i++){
						areaCon+='<span class="searchArea" flag="'+arr_area[i].flag+'"  onclick="onClickAreaSpan(\''+arr_area[i].flag+'\',this)">'+arr_area[i].name+'</span>';
					}
					$("#workConSearch_areaContent").append(areaCon);
				}else{
					if(isHeadquarters){
						if(postid == 'A'){
							arr_post=[{'flag':'B','name':'B'},{'flag':'C','name':'C'}];
						}else if(postid == 'B'){
							arr_post=[{'flag':'C','name':'C'}];
						}else if(postid == 'C'){
							arr_post=[{'flag':'D','name':'D'},{'flag':'E','name':'E'}];
						}else{
							arr_post=[];
						}
					}else{
						if(postid == 'A'){
							arr_post=[{'flag':'B','name':'B'},{'flag':'C','name':'C'},{'flag':'D','name':'D'},{'flag':'E','name':'E'}];
						}else if(postid == 'B'){
							arr_post=[{'flag':'C','name':'C'},{'flag':'D','name':'D'},{'flag':'E','name':'E'}];
						}else if(postid == 'C'){
							arr_post=[{'flag':'D','name':'D'},{'flag':'E','name':'E'}];
						}else{
							arr_post=[];
						}
					}
				}
				for(var i=0;i<arr_post.length;i++){
					postCon+='<span class="searchArea" flag="'+arr_post[i].flag+'"  onclick="onClickPostSpan(\''+arr_post[i].flag+'\',this)" style="width:20px;">'+arr_post[i].name+'</span>';
				}
				$("#workConSearch_postContent").append(postCon);
			}
	  	}
	});
	
	
	
	
};